<?php
class LoginAction extends Action {
    public function index() {
        $this->display();
    }
    public function login() {
        $users = M("employs");
        if ($this->ispost()) {
            if (md5($this->_post("code")) != session("verify")) {
                $this->error("验证码输入错误！");
            } else {
                $data ["empname"] = $this->_post("empname");
                $data ["password"] = md5($this->_post("password"));
                $userarr = $users->where($data)->find();

                if ($userarr ["emp_id"] > 0) {
                    Session("USERNAME", $userarr ["empname"]);
                    Session("USERID", $userarr ["emp_id"]);
                    Session("LOGINID", $userarr ["loginid"]);
                    $upd ["lastlogintime"] = time();
                    $users->where("emp_id=" . $userarr ["emp_id"])->save($upd);
                    $this->success("登录成功！", __APP__);
                    //die();
                } else {
                    $this->error("用户名或密码错误！", __APP__ . "/Login/");
                }
            }
        }
    }

    public function usersel() {
        echo $empname = $this->_get("empname");
    }

    public function loginout() {
        session(null);
        $this->success("退出系统！", __APP__ . "/Login");
    }

    public function ifsession() {
        if (!Session("?LOGINID")) {
            $this->redirect("/Login");
            die();
        }
    }

    Public function verify() {
        import('ORG.Util.Image');
        ob_end_clean();
        Image::buildImageVerify();
    }

}

?>
